
//
//  CardCommentCell.m
//  jiyujiaProgram
//
//  Created by Jame on 15/12/18.
//  Copyright © 2015年 中良 赵. All rights reserved.
//

#import "CardCommentCell.h"
#import "CardCommentModel.h"

@implementation CardCommentCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setCellWithModel:(NSArray *)model WithIndexPath:(NSIndexPath *)index
{
    CardCommentData *data = model[index.row];
    self.nameLabel.text = data.reviewers_name;
    self.commentLabel.text = data.content;
    self.headImage.clipsToBounds = YES;
    self.headImage.layer.cornerRadius = 20;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:data.reviewers_imgUrl] placeholderImage:ECIMAGENAME(@"header.png")];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[data.create_time doubleValue]/1000];
    NSString *dateString = [self compareCurrentTime:date];
    self.timeLabel.text = [NSString stringWithFormat:@"%@",dateString];
    
}


- (NSString *)compareCurrentTime:(NSDate*)compareDate
{
    NSTimeInterval  timeInterval = [compareDate timeIntervalSinceNow];
    timeInterval = -timeInterval;
    long temp = 0;
    NSString *result;
    if (timeInterval < 60) {
        result = [NSString stringWithFormat:@"刚刚"];
    }
    else if((temp = timeInterval/60) <60){
        result = [NSString stringWithFormat:@"%d分前",temp];
    }
    
    else if((temp = temp/60) <24){
        result = [NSString stringWithFormat:@"%d小前",temp];
    }
    
    else if((temp = temp/24) <30){
        result = [NSString stringWithFormat:@"%d天前",temp];
    }
    
    else if((temp = temp/30) <12){
        result = [NSString stringWithFormat:@"%d月前",temp];
    }
    else{
        temp = temp/12;
        result = [NSString stringWithFormat:@"%d年前",temp];
    }
    
    return  result;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
